package com.wolf.etl.core.dialect;

import com.wolf.etl.model.EtlTableModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @author sdyang
 * @create 2019-06-13 11:36
 **/
@Service("SqlServerDialect")
public class SqlServerDialect extends AbstractDialect {

    private static Logger logger = LoggerFactory.getLogger(SqlServerDialect.class);

    private static final String logger_prefix = "wolf-etl#com.wolf.etl.core.dialect#SqlServerDialect";

    @Override
    public String getTableName(EtlTableModel table) {
        String table_name = String.format("%s.%s.[%s]",table.getCatalog(),table.getSchema(),table.getName());
        return table_name;
    }


    @Override
    public String buildPaginationSql(String originalSql, int offset, int rows) {
        String sql = " %s OFFSET %s ROWS FETCH NEXT %s ROWS ONLY";
        return String.format(sql,originalSql,offset,rows);
    }

    @Override
    public String buildInsertSelect(EtlTableModel table, String targerTableName, Map<String, String> fields) {
        return null;
    }
}
